import { NativeModules, Platform } from 'react-native'
const { SIDModule } = NativeModules
// Platform.
const android = Object.freeze(
  Platform.select({
    android: {
      //Android only
      subscribeToAppTokenEvents(callback: (msg: any) => void) {
        SIDModule.subscribeToAppTokenEvents(callback)
      },

      //ELK (Android only)
      subscribeToAnalytic(callback: (msg: any) => void) {
        SIDModule.subscribeToAnalytic(callback)
      },
    },
  }),
)

export default Object.freeze({
  ...android,
  //Initializer
  initialize(
    clientId: string,
    partnerName?: string,
    themeColorLight?: string,
    themeColorDark?: string,
    partnerProfileUrl?: string,
    isShowErrorOnMain?: Boolean,
    standType?: SID_STAND,
  ) {
    SIDModule.initialize(
      clientId,
      partnerName,
      themeColorLight,
      themeColorDark,
      partnerProfileUrl,
      isShowErrorOnMain,
      standType,
    )
  },

  auth(
    scope: string,
    state: string,
    nonce: string,
    redirectUri: string,
    ssoBaseUrl?: string,
    codeChallenge?: string,
    codeChallengeMethod?: string,
    loginHint?: string,
  ) {
    SIDModule.auth(
      scope,
      state,
      nonce,
      redirectUri,
      ssoBaseUrl,
      codeChallenge,
      codeChallengeMethod,
      loginHint,
    )
  },

  loginWithIDWeb(
    scope: string,
    state: string,
    nonce: string,
    redirectUri: string,
    svcRedirectUrlString: string,
    ssoBaseUrl?: string,
    codeChallenge?: string,
    codeChallengeMethod?: string,
    loginHint?: string,
    callback?: (msg: boolean) => void,
  ) {
    SIDModule.loginWithIDWeb(
      scope,
      state,
      nonce,
      redirectUri,
      ssoBaseUrl,
      codeChallenge,
      codeChallengeMethod,
      loginHint,
      svcRedirectUrlString,
      callback,
    )
  },

  logout() {
    SIDModule.logout()
  },

  autoAuth(
    scope: string,
    state: string,
    nonce: string,
    redirectUri: string,
    ssoBaseUrl?: string,
    codeChallenge?: string,
    codeChallengeMethod?: string,
    loginHint?: string,
    callback?: (msg: boolean) => void,
  ) {
    SIDModule.autoAuth(
      scope,
      state,
      nonce,
      redirectUri,
      ssoBaseUrl,
      codeChallenge,
      codeChallengeMethod,
      loginHint,
      callback,
    )
  },

  sendOtherAuth(nameAuthService: string, isSuccess: Boolean, isUserNew: Boolean) {
    SIDModule.sendOtherAuth(nameAuthService, isSuccess, isUserNew)
  },

  setUserID(userID: string) {
    SIDModule.setUserID(userID)
  },

  setClientID(userID: string) {
    SIDModule.setClientID(userID)
  },

  //AppToken
  updateAppToken(
    scope: string,
    clientId: string,
    state: string,
    nonce: string,
    redirectUri: string,
    completion: (error: any, result: any) => void,
    codeChallenge?: string,
    codeChallengeMethod?: string,
  ) {
    SIDModule.updateAppToken(
      scope,
      clientId,
      state,
      nonce,
      redirectUri,
      codeChallenge,
      codeChallengeMethod,
      completion,
    )
  },

  checkAppTokenForValid(callback: (error: any, result: boolean) => void) {
    SIDModule.checkAppTokenForValid(callback)
  },

  goToPartnerSSO(
    webLink: string,
    callback: (error: any, result: any) => void,
    clientId?: string,
    partnerColor?: string,
    openIn?: SID_OPEN_IN_TYPE,
  ) {
    SIDModule.goToPartnerSSO(webLink, clientId, partnerColor, openIn, callback)
  },

  setUIMode(uiMode: COLOR_MODE = COLOR_MODE.AUTO, callback: (msg: any) => void) {
    SIDModule.setUIMode(uiMode, callback)
  },
  setCustomFonts(callback: (msg: any) => void, mediumResID?: number, semiBoldResID?: number) {
    //Тут тоже могут быть вопросы
    SIDModule.setCustomFonts(mediumResID, semiBoldResID, callback)
  },
})

export enum COLOR_MODE {
  LIGHT = 'light',
  DARK = 'dark',
  AUTO = 'auto',
}

export enum SID_STAND {
  PSI_CLOUD_STAND = 'psi_cloud',
  PROM_STAND = 'prom',
  PSI_STAND = 'psi',
  IFT_STAND = 'ift',
  IFT_CLOUD_STAND = 'ift_cloud',
}

export enum SID_OPEN_IN_TYPE {
  WEBVIEW = 'webview',
  BROWSER = 'browser',
}
